Dart.Mail Namespace > MailMessage Class > MailMessage Constructor : MailMessage Constructor(String,String,FileInfo[]) |
Public Function New( _ ByVal text As String, _ ByVal html As String, _ ByVal htmlResources() As FileInfo _ )
Dim text As String Dim html As String Dim htmlResources() As FileInfo Dim instance As New MailMessage(text, html, htmlResources)
public: MailMessage( String^ text, String^ html, array<FileInfo^>^ htmlResources )
Exception | Description |
---|---|
System.ArgumentException | htmlResources missing reference to an HTML link. |
System.ArgumentNullException | html cannot be null or empty. |
This constructor is used to create HTML email. "multipart/alternative" and/or "multipart/related" parts are created to represent the parameters provided.
If text is null or empty, then html and htmlResources are used to create either a "text/html" part or a "multipart/related" part that contains a "text/html" part. Otherwise, Part.ContentType is set to "multipart/alternative" and 2 parts are created and saved in Parts.
If htmlResources is null, then html is represented as a single Htmlpart. Otherwise, a new "multipart/related" Multipart is created and initialized with html and linked htmlResources.
private MailMessage getMessageFromHtml(string pathToHtml, string pathToHtmlResources, string from, string to, string subject, bool includeTextPlain) { //Note: to load a .mht (Mime HTML) file, use MailMessage.Open() instead. //Load HTML string html; using (StreamReader sr = new StreamReader(pathToHtml)) html = sr.ReadToEnd(); //Initialize a MailMessage object. includeTextPlain controls whether the message should include a text/plain part //(which determines whether the message is multipart/alternative (when true) or multipart/related (when false)) string textPlain = (includeTextPlain) ? "text/plain representation of included HTML" : null; MailMessage mailMsg = new MailMessage(textPlain, html, new DirectoryInfo(pathToHtmlResources).GetFiles()); //Set sender, recipients and subject mailMsg.From = from; mailMsg.To = to; mailMsg.Subject = subject; return mailMsg; }
Private Function getMessageFromHtml(ByVal pathToHtml As String, ByVal fromAddress As String, ByVal toAddress As String, ByVal subject As String) As MailMessage 'Note: to load a .mht (Mime HTML) file, use MailMessage.Open() instead. 'Load HTML Dim sr As New StreamReader(pathToHtml) Dim html As String = sr.ReadToEnd() sr.Close() 'Initialize a MailMessage object. includeTextPlain controls whether the message should include a 'text/plain part (which determines whether the message is multipart/alternative (when true) or multipart/related (when false)) Dim textPlain As String = If(includeTextPlain, "text/plain representation of included HTML", Nothing) Dim mailMsg As New MailMessage(textPlain, html, New DirectoryInfo(pathToHtmlResources).GetFiles()) 'Set sender, recipients and subject mailMsg.From = fromAddress mailMsg.To = toAddress mailMsg.Subject = subject Return mailMsg End Function